import java.util.HashMap;

/**
 * @projectName: LeetCode
 * @package: PACKAGE_NAME
 * @className: Point1
 * @author: Mocrash
 * @description: TODO
 * @date: 2024/10/14 9:47
 * @version: 1.0
 */
public class Point1 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = new int[]{1, 2, 3, 4, 5, 5};
        int[] ints = solution.twoSum(nums, 10);
        for (int anInt : ints) {
            System.out.println(anInt + " : " + nums[anInt]);
        }
    }

    //java:两数之和
    static class Solution {
        public int[] twoSum(int[] nums, int target) {
            HashMap<Integer, Integer> hashMap = new HashMap<>();
            for (int i = 0; i < nums.length; i++) {
                int complement = target - nums[i];
                if (hashMap.containsKey(complement)) {
                    return new int[]{hashMap.get(complement), i};
                }
                hashMap.put(nums[i], i);
            }
            return null;
        }
    }
}

